package com.sig.player.model;

import com.sig.common.event.EventDispatcher;
import com.sig.common.event.GeneralEventListener;
import com.sig.player.event.PlayerEvent;

/**
 * 玩家实体抽象
 *
 * @author sig
 * @since 2019/2/21
 */
public abstract class AbstractPlayer<T extends PlayerEntity> implements Player {
    /** 事件派发器 */
    protected EventDispatcher<PlayerEvent> dispatcher = new EventDispatcher<>();
    /** 玩家实体 */
    protected  T playerEntity;

    public T playerEntity() {
        return playerEntity;
    }

    @Override
    public boolean dispatchEvent(PlayerEvent event) {
        event.setDispatcher(this);
        return dispatcher.dispatchEvent(event);
    }

    public void addEventListener(Class<? extends PlayerEvent> eventType, GeneralEventListener<PlayerEvent> listener) {
        dispatcher.addEventListener(eventType, listener);
    }

    public boolean removeEventListener(Class<? extends PlayerEvent> eventType, GeneralEventListener<PlayerEvent> listener) {
        return dispatcher.removeEventListener(eventType, listener);
    }

    public void reset() {
        dispatcher.reset();
    }

    public boolean hasEventListener(Class<? extends PlayerEvent> eventType) {
        return dispatcher.hasEventListener(eventType);
    }

    public boolean hasEventListener(Class<? extends PlayerEvent> eventType, GeneralEventListener<PlayerEvent> listener) {
        return dispatcher.hasEventListener(eventType, listener);
    }

    public boolean hasEventListener(Class<? extends PlayerEvent> eventType, Class<? extends GeneralEventListener<PlayerEvent>> listener) {
        return dispatcher.hasEventListener(eventType, listener);
    }
}
